<?php
/**
 * api模块中间件
 */

namespace app\api\middleware;

use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;

/**
 * 跨域处理中间件
 */
class CrossDomain implements MiddlewareInterface
{
    public function process(Request $request, callable $handler): Response
    {
        if ($request->method() === 'OPTION') {
            // TODO::这里的header可考虑改成原样返回
            return \response()->withHeaders(config('api.cross_domain')['header']);
        }
        // 请求继续向洋葱芯穿越
        return $handler($request);
    }
}
